#ifndef _MEMBLOCK_H_CSEAPI_
#define _MEMBLOCK_H_CSEAPI_

class CSE_IMPEXP_IN TAbsStream
{
public:
    virtual TBool isEnd(size_t position);
    virtual size_t seek(int offset, int origin);
    virtual size_t tell();
    virtual size_t read(char *buffer, size_t count);
    virtual size_t write(const char *buffer, size_t count);
    virtual void flush();
};

class CSE_IMPEXP_IN TMemAbsStream: public TAbsStream
{
public:
    virtual char *addr();
    virtual int len();
};

class CSE_IMPEXP_IN TFixedStream: public TMemAbsStream
{
protected:
    char *m_data;
    size_t m_position;
    size_t m_length;

public:
    TFixedStream();
    TFixedStream(char *buff, size_t iLen);
    ~TFixedStream();

    TFixedStream& operator=(const TFixedStream& stream);

    char *addr();
    int len();

    TBool isEnd(size_t position);
    size_t seek(int offset, int origin);
    size_t tell();
    size_t read(char *buffer, size_t count);
    size_t write(const char *buffer, size_t count);
};

class CSE_IMPEXP_IN TMemBlock
{
private:
    TMemBlock(const TMemBlock& block); // disable copy construct

protected:
    TInt8 *m_data;

public:
    TMemBlock();
    TMemBlock(int iSize);
    TMemBlock(int MagicNum, TMemBlock& block);
    TMemBlock(TInt8 *addr);
    ~TMemBlock();

    TMemBlock(TFixedStream& stream, int iSize);

    TInt8& operator[](int index) const;
    TMemBlock slice(int index, int iLen) const;

    TBool isEmpty() const;
    TInt8 *addr() const;
    TInt8 *transfer(TInt8 *pOther);
};

#endif
